package com.yinhe.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.system.domain.YhRelationshipTransfer;
import com.yinhe.system.service.IYhRelationshipTransferService;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.common.core.page.TableDataInfo;

/**
 * 关系转接Controller
 * 
 * @author yinhe
 * @date 2022-09-24
 */
@RestController
@RequestMapping("/system/transfer")
public class YhRelationshipTransferController extends BaseController
{
    @Autowired
    private IYhRelationshipTransferService yhRelationshipTransferService;

    /**
     * 查询关系转接列表
     */
    @PreAuthorize("@ss.hasPermi('system:transfer:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhRelationshipTransfer yhRelationshipTransfer)
    {
        startPage();
        List<YhRelationshipTransfer> list = yhRelationshipTransferService.selectYhRelationshipTransferList(yhRelationshipTransfer);
        return getDataTable(list);
    }

    /**
     * 导出关系转接列表
     */
    @PreAuthorize("@ss.hasPermi('system:transfer:export')")
    @Log(title = "关系转接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhRelationshipTransfer yhRelationshipTransfer)
    {
        List<YhRelationshipTransfer> list = yhRelationshipTransferService.selectYhRelationshipTransferList(yhRelationshipTransfer);
        ExcelUtil<YhRelationshipTransfer> util = new ExcelUtil<YhRelationshipTransfer>(YhRelationshipTransfer.class);
        util.exportExcel(response, list, "关系转接数据");
    }

    /**
     * 获取关系转接详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:transfer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhRelationshipTransferService.selectYhRelationshipTransferById(id));
    }

    /**
     * 新增关系转接
     */
    @PreAuthorize("@ss.hasPermi('system:transfer:add')")
    @Log(title = "关系转接", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhRelationshipTransfer yhRelationshipTransfer)
    {
        return toAjax(yhRelationshipTransferService.insertYhRelationshipTransfer(yhRelationshipTransfer));
    }

    /**
     * 修改关系转接
     */
    @PreAuthorize("@ss.hasPermi('system:transfer:edit')")
    @Log(title = "关系转接", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhRelationshipTransfer yhRelationshipTransfer)
    {
        return toAjax(yhRelationshipTransferService.updateYhRelationshipTransfer(yhRelationshipTransfer));
    }

    /**
     * 删除关系转接
     */
    @PreAuthorize("@ss.hasPermi('system:transfer:remove')")
    @Log(title = "关系转接", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhRelationshipTransferService.deleteYhRelationshipTransferByIds(ids));
    }
}
